# IRCII Trivia Script v2.0 # Copyright (c) 2001-2005 Bernard Yen (Seeker on IRC) # V 1.1.0 Initial release. Created by Bernard Yen. # V 2.0 Adapted and updated for Snak 5 by Kent Sorensen. # All support questions for version 2.0 must be sent to kents@snak.com # Improved saving. # Removed setting of homedir and rmcmd # Added mkdir for TriviaScript directory in your home folder # Moved trivia.sav file to TriviaScript directory # Changed all calls to say to trivsay which uses the -t flag to direct the message to the channel that was active when the script was loaded # Removed the need to authenticate, and took out the passwords # Questions are answered in the channel # Took out storage of wrong answers. This can't be maintained when questions are answered in the channel. # The penalties are also gone.. # Renamed auth_help to update_stats # Only one correct answer per question # !start no longer required the admin password # Removed the duel system as it won't fit the current model # Remind user to change admin password on first launch # -------------------------------------------------------------------------- # This software is provided 'as-is', without any expressed or implied # warrenty. In no event will the author be held liable for any damages # arising from the use of this software. # # Permissing is granted to anyone to use this software for non-commercial # purposes and to alter and redistribute it freely, subject to the # following restrictions: # # 1. The origin of this software must not be misrepresented; you must not # claim that you wrote the original software. If you use this software in # a product, an acknowledgement in the product documentation is required. # # 2. Altered source versions must be plainly marked as such, and must not # be misrepresented as being the original software # # 3. This notice may not be removed or altered from any source distribution. # # -------------------------------------------------------------------------- # --- Program Constant Declarations --- # Limit on how long each question is posed for in seconds @trivia.LIMIT.1 = 30 @trivia.LIMIT.2 = 25 @trivia.LIMIT.3 = 20 @trivia.LIMIT.4 = 20 @trivia.LIMIT.5 = 20 # Number of seconds to pause between questions @trivia.BREAK = 10 # Number of seconds to pause between final score and start of wagering. Note that # the actual time between display of score and wagering start is WAGERWAIT - BREAK # since both timers are started at the same time. @trivia.WAGERWAIT = 30 # Number of seconds to pause between start of wagering and end of wagering. @trivia.WAGERTIME = 30 # Number of rounds available in one game, excluding wagering round. @trivia.MAXROUND = 4 # Number of questions for each round. Last round must have exactly 1 question. @trivia.QU.1 = 5 @trivia.QU.2 = 5 @trivia.QU.3 = 5 @trivia.QU.4 = 5 @trivia.QU.5 = 1 # Maximum number of daily double questions per round. @trivia.SUDDENDEATH = 3 # Probability of daily double questions appearing (1/PROBDEATH). @trivia.PROBDEATH = 8 # Proportion of regular round's point to give to player if they get daily double questions right. # The final award is (round's point)*trivia.AWARDDEATH. @trivia.AWARDDEATH = 2 # Amount of points awarded for each round. Last round is 0 points since it is the wagering # round, and people cannot obtain additional points for getting it right. @trivia.P.1 = 1 @trivia.P.2 = 2 @trivia.P.3 = 4 @trivia.P.4 = 8 @trivia.P.5 = 0 # Administrative password -- required for all admin commands. @trivia.ADMINPASS = [default] # Valid commands that can be sent to the bot. @trivia.VALIDCMD = [!start !stop !reset !add !sub !wipe !save !title !title_kill] # Valid admin commands that can be sent to the bot. @trivia.VALIDADMINCMD = [!stop !reset !add !sub !wipe !save] # Rank above which player can create their own title. @trivia.MAXRANK = 1000 # People who have helped on this project and deserves special mention. @trivia.THANKYOU = [chibi_k, dunno001, Hisoka, InuTrunks, IPChan, Klepto, Knotz, lego, Mike-hime, melz, NFD, Teppei, XObadboy, xxloloxx] # Version of the trivia script. @trivia.VERSION = [2.0] # --- file saving stuff --- # Snak adaptation 1.1.1 make trivia store its file in a subdirectory to home EVAL /comment $mkdir(${HOME}/TriviaScript) @ trivia.SAVEFILE = [trivia.sav] # --- Channel Name is the active channel when the script was loaded --- # can be changed later with /triviachannel @trivia.channel = [$C] # --- Global Variables --- # People who have answered the current question correctly @trivia.curques = [] # Flag indicating whether a game is running (0:NO, 1:YES) @trivia.current = 0 # Current trivia round number @trivia.round = 0 # Questions remaining in current round @trivia.remaining = 0 # Question number of current round being asked @trivia.quesnum = 0 # Flag indicating whether there is a question being shown right now @trivia.active = 0 # A list of all used questions since the robot has been started @trivia.usedques = [] # Flag indicating whether bonus points are given @trivia.bonus = 0 # Flag indicating whether wagering is allowed @trivia.wager = 0 # Flag to fix problems with the compare function during wagering @trivia.wager_special = 0 # Count of the number of sudden death questions which has appeared @trivia.amtdeath = 0 # Flag indicating whether current question is a sudden death question @trivia.deathflag = 0 # Flag indicating whether the question list is loaded @trivia.qloaded = 0 # A question timer to display how fast the players responds to the question @trivia.timer = 0 # --- Start of program code. Do not modify anything below this line. --- alias triviachannel { @trivia.channel = [$0] } alias trivsay { say -t $trivia.channel $- } alias trivia { # Load the auxilary question file into memory if not loaded yet. if (!trivia.qloaded) { $loadq() } # Load the saved variables from file. if (!trivia.stat_loaded) { /load -p ${HOME}/TriviaScript/$trivia.SAVEFILE } # Check whether a game is currently running. Give an error if there is. if (trivia.current == 0) { @trivia.current = 1 # Print out the trivia header (copyright, thank you note, trivia record holder) trivsay Trivia v$trivia.VERSION Copyright 2002-2005 by 5Seeker trivsay Support questions must be sent to Kent Sorensen - kents@snak.com trivsay Type !help for a list of available commands trivsay if (trivia.ADMINPASS == [default]) { echo Your administrator password has not been changed from 'default' echo Please type /adminpass } if (!trivia.bestscore || trivia.bestscore == 0) { trivsay Highest Trivia Record:5 None @4 0 point } { if (trivia.bestscore == 1) { trivsay Highest Trivia Record:5 $trivia.bestname @4 1 point } { trivsay Highest Trivia Record:5 $trivia.bestname @4 $trivia.bestscore points } } trivsay score # Initialize the randomizer, clear global variables, and show the first question. @trivia.correct = 0 @trivia.round = 0 @trivia.remaining = 0 @trivia.quesnum = 0 @trivia.remaining = 0 @trivia.active = 0 @trivia.wager = 0 @trivia.wager_special = 0 @trivia.amtdeath = 0 @trivia.deathflag = 0 @trivia.randomvar = trivia.randomvar + 1 @trivia.seed = [$time()] + trivia.randomvar $srand($trivia.seed) $show_question() } { trivsay [ERROR] Please wait until the current game ends before starting another } } # Load or reload the question into memory so it can be used by this script. alias loadq { ^load trivia_question.txt } # Show a question based on the round number. Higher rounds are more difficult. $0 controls whether the # wagering round is on (0:NO, 1:YES). alias show_question { # Clear global variables. @trivia.curques = [] # If no more questions available in this round, move to next round and reset question number. if (!trivia.remaining) { @trivia.quesnum = 1 @trivia.round= trivia.round + 1 @trivia.remaining = trivia[QU][$trivia.round] } { @trivia.quesnum = trivia.quesnum + 1 } # Set expiration timer for current question. If we are in wagering round, queue up $calc_wager to be called. if ([$0] == 1) { ^timer -refnum 1 $trivia[LIMIT][$trivia.round] /calc_wager } { ^timer -refnum 1 $trivia[LIMIT][$trivia.round] /question_timed_out } # Find the maximum number of question available on the current difficulty level and choose # one of them. If the question has been posed already, choose another one. @trivia.catques = trivia[C][$trivia.round] @trivia.pick = rand($trivia.catques) + 1 while ([$match($trivia.round*$trivia.pick $trivia.usedques)]) { @trivia.pick = rand($trivia.catques) + 1 } # Add question to used question list (format round*quesnum) ^assign trivia.usedques $trivia.usedques $trivia.round*$trivia.pick ^assign trivia.temp $trivia[A][$trivia.round][$trivia.pick] ^assign trivia.temp $#trivia.temp # Potentially make this question a daily double question, but the wagering round cannot # be turned into a daily double, so additional checks are done. If the question turns out # to be a daily double, we increment $trivia.amtdeath by 1 to keep track. @trivia.deathflag = 0 if ((trivia.amtdeath < trivia.SUDDENDEATH) && (trivia.round <= trivia.MAXROUND)) { if (rand($trivia.PROBDEATH) == 0) { @trivia.deathflag = 1 @trivia.amtdeath = trivia.amtdeath + 1 } } @trivia.temptitle = [=== Round $trivia.round Question $trivia.quesnum Time Limit: $trivia[LIMIT][$trivia.round] seconds] if (!trivia.deathflag) { if (trivia[P][$trivia.round] > 0) { if (trivia[P][$trivia.round] == 1) { @trivia.temptitle = trivia.temptitle##[ >>1 point per question<< ===] } { @trivia.temptitle = trivia.temptitle##[ >>$trivia[P][$trivia.round] points per question<< ===] } } { # in the wagering round @trivia.temptitle = trivia.temptitle##[ ===] } } { if (trivia[P][$trivia.round] > 0) { @trivia.tempcalc = trivia.AWARDDEATH * trivia[P][$trivia.round] @trivia.temptitle = trivia.temptitle##[ >>DAILY DOUBLE $trivia.tempcalc points per question<< ===] } { @trivia.temptitle = trivia.temptitle##[ >>DAILY DOUBLE<< ===] } } trivsay $trivia.temptitle ^assign -trivia.temptitle if ([$0] == 1) { trivsay Type 4/msg $N  to answer wagering question } # If the answer is a number (i.e. trivia.Q.R.P.N is defined), don't print out the number of words # so people are not confused. if (trivia[Q][$trivia.round][$trivia.pick][N]) { trivsay [4Q] 3$trivia[Q][$trivia.round][$trivia.pick] \ } { if (trivia.temp == 1) { trivsay [4Q] 3$trivia[Q][$trivia.round][$trivia.pick] \<$trivia.temp word\> } { trivsay [4Q] 3$trivia[Q][$trivia.round][$trivia.pick] \<$trivia.temp words\> } } # Start the timer so we can record down how fast the players answer the question. Also # activate the trivia.active flag to indicate that there is an active question. @trivia.timer = time() @trivia.active = 1 } # This function parses messages that the bot may receive. It processes both commands which begin # with a "!" and regular answers. If there are no active question, all msgs are treated as regular # text which is not processed (except commands, which are still processed). alias handle_public { if (word(0 $1-) == [!start]) { ^timer 1 /trivia } { if (word(0 $1-) == [!help]) { # Help system which private notices a help menu to people who type !help in the channel. ^notice $0 Please type 4/msg $N !help to receive help on specific topics: ^notice $0 01. General info: copyright, general, start_game ^notice $0 02. Special features: daily_double ^notice $0 03. Stat related: title, title_kill ^notice $0 04. Admin control: add, reset, save, start, stop, sub, wipe } { if (!trivia.active) { # Normal message, don't do anything. } { # If it is the wagering round but they don't have points, they are not allowed to answer. if ((trivia.round == (trivia.MAXROUND + 1)) && !trivia[SCORE][$encode($0)]) { ^notice $0 [ERROR] You need at least 1 point to answer in the wagering round. } { # Check the real answer. $compare($0 $1-) } } } } } # Handles commands embedded in the incoming private messages. If the command requires special # authorization, this function checks the admin password before passing the command on to # $parse_admin(). alias handle_private { # Parsing of wagering messages. if (trivia.wager && word(0 $1-) == [!wager]) { # Check to make sure there is a valid wager, meaning $2 exist and is a positive integer. We also # check whether the player has enough points. @trivia.temp = strip(abcdefghijklmnopqrstuvwxyz. $tolower($2)) if (!trivia.temp || trivia.temp <= 0 || trivia.temp > trivia[SCORE][$encode($0)]) { ^notice $0 [ERROR] Command is !wager where amount more than 0 but less than your score. } { if (trivia.temp == 1) { ^notice $0 You have chosen to wager5 $trivia.temp point. } { ^notice $0 You have chosen to wager5 $trivia.temp points. } # This is a validated wager, so go ahead and place it (exits function). $putwager($0 $trivia.temp) } } # Determine whether they are messaging a valid command. If so, go to command parsing. # Otherwise, go to message parsing. if (match($word(0 $1-) $trivia.VALIDCMD)) { # !title, !title_kill are used for the personal stat system. if (word(0 $1-) == [!title]) { @trivia.tempnet = trivia[SCORE][$encode($0)] if (trivia.tempnet < trivia.MAXRANK) { ^notice $0 [ERROR] Sorry, but your rank is not high enough to use this command. } { if (!word(1 $1-)) { ^notice $0 [ERROR] Command is !title . } { ^timer 1 /change_title $0 $2- } } } if (word(0 $1-) == [!title_kill]) { if (trivia[SELF_TITLE][$encode($0)] != []) { ^assign -trivia[SELF_TITLE][$encode($0)] ^notice $0 Your customized title has been successfully removed. } { ^notice $0 [ERROR] Sorry, but you do not have a customized title to delete. } } if (word(0 $1-) == [!start]) { ^timer 1 /trivia } # !stop, !reset, !add, !sub, !wipe are admin cmds which require the # admin password. Do not put non-admin commands below here because the admin password is # checked at this point. Normal commands will fail. if (!match($word(0 $1-) $trivia.VALIDADMINCMD)) { # Don't do anything since this is not an admin command. } { if (word(1 $1-) != trivia.ADMINPASS) { ^notice $0 [ERROR] The admin password you provided is not correct. } { $parse_admin($0 $1-) } } } { if (word(0 $1-) == [!help]) { if (word(1 $1-) == [copyright]) { ^notice $0 The full content of this script as well auxilary support files are copyrights of Bernard Yen. You are allowed to modify and distribute the script on a non-profit basis, but changes must be clearly stated and not misrepresented as the original. } if (word(1 $1-) == [general]) { ^notice $0 There are $trivia.MAXROUND rounds every game, followed by a wagering round where you can potentially double your score. Points are allocated as $trivia.P.1, $trivia.P.2, $trivia.P.3, and $trivia.P.4 respectively for the $trivia.MAXROUND rounds. Approximately 2 questions per game are daily double questions that carry greater award. To answer, simply type the answer in the channel. } if (word(1 $1-) == [start_game]) { ^notice $0 You can start a game of trivia at any time by typing !trivia start into the trivia channel, but please note that only an admin can stop the game while it is in progress. } # Special features help system if (word(1 $1-) == [daily_double]) { ^notice $0 Every game, there are approximately 2 questions that will have "daily double" after them. Getting those correct will give you double the normal points, but getting them incorrect will cause you to lose half of what the round is worth. If the round is normally worth 2 points, you could potentially gain 4 points or lose 2 points per guess. } # Stat commands help system if (word(1 $1-) == [title]) { ^notice $0 By typing /msg $N !title after you reach a rank of at least $trivia.MAXRANK, you will be able to create a customized title for your personal stat database display. } if (word(1 $1-) == [title_kill]) { ^notice $0 By typing /msg $N !title_kill you can delete your customized title. } # Admin control help system if (word(1 $1-) == [add]) { ^notice $0 By typing /msg $N !add <adm_pass> <nick> <pts> you can add points to a specified player. } if (word(1 $1-) == [reset]) { ^notice $0 By typing /msg $N !reset <adm_pass> you can reset the used question list. } if (word(1 $1-) == [save]){ ^notice $0 By typing /msg $N !save <adm_pass> you can save trivia variables to the file. Please note that this is currently buggy and may cause unexpected crashes. } if (word(1 $1-) == [start]) { ^notice $0 By typing !start in the channel you can start a game of trivia if it is stopped. } if (word(1 $1-) == [stop]) { ^notice $0 By typing /msg $N !stop <adm_pass> you can stop a game of trivia. } if (word(1 $1-) == [sub]) { ^notice $0 By typing /msg $N !sub <adm_pass> <nick> <pts> you can subtract points from a specified player. } if (word(1 $1-) == [wipe]) { ^notice $0 By typing /msg $N !wipe <adm_pass> <nick> where nick is a case sensitive nickname, you can wipe the personal stat database of the specified player. } } { # is this a valid answer $compare($0 $1-) } } } # Changes the title of an individual player. This function is assumed only accessible after a # player achieves the minimum rank of trivia.MAXRANK. alias change_title { ^assign trivia[SELF_TITLE][$encode($0)] $1- ^notice $0 Your title has been successfully changed. } # Handles the parsing of admin commands. This function assumes that when it is being called, the # admin password has already been verified. alias parse_admin { if (word(0 $1-) == [!stop]) { /endtrivia } if (word(0 $1-) == [!reset]) { ^timer 1 /reset_used $0 } if (word(0 $1-) == [!wipe]) { if (!word(2 $1-)) { ^notice $0 [ERROR] Command is !wipe <admin password> <nick>. } { ^timer 1 /wipe_stat $0 $word(2 $1-) } } if (word(0 $1-) == [!save]) { /sve ^notice $0 The current game stats have been saved. } if (word(0 $1-) == [!add]) { if (!word(2 $1-) || !word(3 $1-)) { ^notice $0 [ERROR] Command is !add <password> <nick> <amt>. } { ^assign trivia.tempmsg $0 ^assign trivia.temppts $word(3 $1-) ^userhost $word(2 $1-) -cmd ^assign trivia.tempadd $$0 ^userhost $word(2 $1-) -cmd if ([$3]){ ^timer 1 /add_score $trivia.tempmsg $trivia.tempadd $trivia.temppts } { ^notice $trivia.tempmsg [ERROR] Player does not exist on the IRC server. } } } if (word(0 $1-) == [!sub]) { if (!word(2 $1-) || !word(3 $1-)) { ^notice $0 [ERROR] Command is !sub <password> <nick> <amt>. } { ^assign trivia.tempmsg $0 ^assign trivia.temppts $word(3 $1-) ^userhost $word(2 $1-) -cmd ^assign trivia.tempadd $$0 ^userhost $word(2 $1-) -cmd if ([$3]){ ^timer 1 /sub_score $trivia.tempmsg $trivia.tempadd $trivia.temppts } { ^notice $trivia.tempmsg [ERROR] Player does not exist on the IRC server. } } } } # Completely wipes a player's personal stat database. The first parameter is the person who invoked # this function, and the second parameter is the nickname to wipe. alias wipe_stat { # Load the stat file if not loaded yet. if (!trivia.stat_loaded) { /load -p ${HOME}/TriviaScript/$trivia.SAVEFILE } # Don't let admins wipe stat during a game, or else weird things might happen. if (trivia.current) { ^notice $0 [ERROR] You cannot use the !wipe command when a game is running. } { ^assign -trivia[SCORE][$encode($1)] ^notice $0 $1's personal stat database has been successfully wiped. } } # Increase the score of player $1 by $2 points. alias add_score { @trivia.temp = [$2] if (trivia[SCORE][$encode($1)]) { @trivia[SCORE][$encode($1)] = trivia[SCORE][$encode($1)] + trivia.temp } { @trivia[SCORE][$encode($1)] = trivia.temp } ^notice $0 $1's score has been successfully changed. } # Decrease the score of player $0 by $1 points. alias sub_score { @trivia.temp = [$2] @trivia[SCORE][$encode($1)] = trivia[SCORE][$encode($1)] - trivia.temp ^notice $0 $1's score has been successfully changed. } # Place the wager for the player by assigning it to $trivia[WAGER][$encode($0)]. alias putwager { @trivia[WAGER][$encode($0)] = [$1] } # Because the normal match procedure only matches one word, the match_all procedure is used # to match all words. alias match_all { @trivia.counter = 0 @function_return = 1 # Determine which answer to use @trivia.temp = trivia[A][$trivia.round][$trivia.pick] while (trivia.counter < [$#trivia.temp]) { # Perform some generic pattern matching with pluaral and non-plural words. @trivia.tempword = word($trivia.counter $trivia.temp) if (right(1 $trivia.tempword) == [s] && right(3 $trivia.tempword) != [ies]) { @trivia.tempword2 = left(${@trivia.tempword - 1} $trivia.tempword) } { if (right(1 $trivia.tempword) == [y]) { @trivia.tempword2 = left(${@trivia.tempword - 1} $trivia.tempword)##[ies] } { if (right(3 $trivia.tempword) == [ies]) { @trivia.tempword2 = left(${@trivia.tempword - 3} $trivia.tempword)##[y] } { @trivia.tempword2 = trivia.tempword##[s] } } } # Perform some common typo matching between 'e' and 'i', 'l' and 'r', 'k' and 'c', 'j' and 'z', 'h' and 'u', 'o' and 'u'. @trivia.guessn1 = strip(ei $1-) @trivia.guessn2 = strip(lr $1-) @trivia.guessn3 = strip(kc $1-) @trivia.guessn4 = strip(jz $1-) @trivia.guessn5 = strip(hu $1-) @trivia.guessn6 = strip(ou $1-) @trivia.ansn1 = strip(ei $trivia.tempword) @trivia.ansn2 = strip(lr $trivia.tempword) @trivia.ansn3 = strip(kc $trivia.tempword) @trivia.ansn4 = strip(jz $trivia.tempword) @trivia.ansn5 = strip(hu $trivia.tempword) @trivia.ansn6 = strip(ou $trivia.tempword) if (![$match($trivia.tempword $1-)] && ![$match($trivia.tempword2 $1-)] && ![$match($trivia.ansn1 $trivia.guessn1)] && ![$match($trivia.ansn2 $trivia.guessn2)] && ![$match($trivia.ansn3 $trivia.guessn3)] && ![$match($trivia.ansn4 $trivia.guessn4)] && ![$match($trivia.ansn5 $trivia.guessn5)] && ![$match($trivia.ansn6 $trivia.guessn6)]) { @function_return = 0 } @trivia.counter = trivia.counter + 1 } } # Given the question number, this compares the inputted answer with the correct answer # using pattern matching. This function also performs score keeping. alias compare { @trivia.finalscore = 0 @trivia.correct = match_all(0 $1-) # If correct answer and they have not answered already. if (trivia.correct){ if (![$match($0 $trivia.curques)]) { # Assign person to people who have already answered the current question correctly. ^assign trivia.curques $trivia.curques $0 # update scores if this is a normal round if (trivia.round <= trivia.MAXROUND) { # Initiate a personal score variable. We must encode the text since some of the # characters in a nickname cannot be part of a variable. If the variable already exists # then add the scores on. We also add the encoded text to a global list so we can remove # all the variables in the end. ^assign trivia.finalscore $trivia[P][$trivia.round] # If the question is sudden death, increase the score the player receive, include the bonus # points incurred. if (trivia.deathflag) { @trivia[SCORE][$encode($0)] = trivia[SCORE][$encode($0)] + trivia.AWARDDEATH * trivia.finalscore } { @trivia[SCORE][$encode($0)] = trivia[SCORE][$encode($0)] + trivia.finalscore } if (trivia[SCORE][$encode($0)] > 1) { trivsay Check out the big brain on $0 ! New score $trivia[SCORE][$encode($0)] points ! } { trivsay Way to go $0 ! Welcome to the game. You now have $trivia[SCORE][$encode($0)] point ! } new_question } } { # If they answered the question already ^notice $0 [ERROR] You have already answered this trivia question! } } } # Stops the current trivia challenge round and begin a new one after specified break time. alias question_timed_out { trivsay === Round $trivia.round Question $trivia.quesnum Time Limit Expired === trivsay The answer was4 $toupper($trivia[A][$trivia.round][$trivia.pick]). new_question } # begin a new round alias new_question { ^timer -delete 1 # Decrease the remaining question by one. @trivia.remaining = trivia.remaining - 1 # If we are in final round and there is no more question, announce the final scores and go into # wagering mode. Otherwise set up a timer to show the next question. ^timer -delete 2 if ((trivia.round == trivia.MAXROUND) && (trivia.remaining == 0)) { ^timer -delete 3 ^timer -refnum 3 $trivia.BREAK /score ^timer -refnum 2 $trivia.WAGERWAIT /start_wager @trivia.active = 0 } { ^timer -refnum 2 $trivia.BREAK /show_question } @trivia.active = 0 } # Start the wagering process by announcing the start of wagering and waiting $trivia.WAGERTIME. alias start_wager { @trivia.wager = 1 @trivia.round = trivia.MAXROUND + 1 @trivia.remaining = 1 @trivia.quesnum = 0 trivsay === Wagering Round For $trivia.channel Trivia === trivsay To wager,4 /msg $N !wager <amount> where amount is less than or equal to your total score. trivsay You have4 $trivia.WAGERTIME seconds to place your wagers if you choose to participate. ^timer -refnum 5 $trivia.WAGERTIME /stop_wager } # Stops the wagering process by dropping the wager flag and showing the final question. alias stop_wager { # Special form of $show_question causing the timer to call $calc_wager() when the timer expires # instead of the regular $stop(). @trivia.wager = 0 @trivia.wager_special = 1 $show_question(1) } # Clear out the used question list. alias reset_used { @trivia.usedques = [] ^notice $0 The used question list has been reset successfully. } # Terminate the trivia program. ($0 == 1 means normal quit; $0 == 0 means abnormal) alias endtrivia { @trivia.winnerscore = 0 if (![$0]) { trivsay Trivia terminated at administator request. foreach trivia.SCORE ii { ^assign -trivia[WAGER][$ii] } } { # Clear out all player scores according to the global record list. Print out all # the scores, and delete the score variables. trivsay === Final Results For $trivia.channel Trivia === foreach trivia.SCORE ii { # Update the top trivia record if the old one has been broken if (trivia[SCORE][$ii] > trivia.bestscore) { @trivia.bestscore = trivia[SCORE][$ii] @trivia.bestname = decode($ii) } # Determine the top score of this game if (trivia[SCORE][$ii] > trivia.winnerscore) { @trivia.winnerscore = trivia[SCORE][$ii] } } score # clean up foreach trivia.SCORE ii { ^assign -trivia[WAGER][$ii] } } # Clear out all the global variables and timers so weird things don't happen. if (trivia.active) { ^timer -delete 1 } { ^timer -delete 2 } @trivia.current = 0 trivsay === Type !start to start another round of trivia === } # Calculate the wager results based on what players wagered. alias calc_wager { @trivia.active = 0 trivsay === Wagering round is over === trivsay The answer was4 $toupper($trivia[A][$trivia.round][$trivia.pick]). @trivia.wager_result = [] foreach trivia.SCORE ii { # If they got the wagering question correct, add the wager. Otherwise, subtract it. if (trivia[WAGER][$ii]) { if (match($decode($ii) $trivia.curques)) { @trivia[SCORE][$ii] = trivia[SCORE][$ii] + trivia[WAGER][$ii] @trivia.wager_result = trivia.wager_result##[4 $decode($ii) won $trivia[WAGER][$ii] points ] } { @trivia[SCORE][$ii] = trivia[SCORE][$ii] - trivia[WAGER][$ii] @trivia.wager_result = trivia.wager_result##[4 $decode($ii) lost $trivia[WAGER][$ii] points ] } } } trivsay $trivia.wager_result $endtrivia(1) } # Prints out the score of each player whose score is non-zero. alias score { @trivia.temp = [Current Scores: ] foreach trivia.SCORE ii { if (trivia[SCORE][$ii] == 1 || trivia[SCORE][$ii] == 0) { @trivia.temp = trivia.temp##[4 $decode($ii) $trivia[SCORE][$ii] point] } { @trivia.temp = trivia.temp##[4 $decode($ii) $trivia[SCORE][$ii] points] } } trivsay $trivia.temp } # Checks to see whether $0 has any points. If so, we move all those points to $1 and delete # the original record. Otherwise, just ignore the event. alias update_name { # Process nickname change only if they have score ­ 0 if (trivia[SCORE][$encode($0)]) { # Transfer points over to new nick @trivia[SCORE][$encode($1)] = trivia[SCORE][$encode($0)] # Delete old nick so it's not displayed ^assign -trivia[WAGER][$encode($0)] ^assign -trivia[SCORE][$encode($0)] } } # Converts a given amount of questions into an appropriate title alias q_to_title { # If they have own title and rank is high enough, use that instead @trivia.tempnet = trivia[SCORE][$encode($1)] if (trivia[SELF_TITLE][$encode($1)] != [] && trivia.tempnet >= trivia.MAXRANK) { @function_return = [6$trivia[SELF_TITLE][$encode($1)]] } { if ([$0] < 0) { @function_return = [Court Jester] } { if ([$0] < 10) { @function_return = [Lowly Slime Mold] } { if ([$0] < 20) { @function_return = [Growing Slime Mold] } { if ([$0] < 30) { @function_return = [Regular Slime Mold] } { if ([$0] < 40) { @function_return = [Strong Slime Mold] } { if ([$0] < 50) { @function_return = [Slime Mold Master] } { if ([$0] < 60) { @function_return = [Smelly Fungus] } { if ([$0] < 70) { @function_return = [Fresh Fungus] } { if ([$0] < 80) { @function_return = [Kawaii Fungus] } { if ([$0] < 90) { @function_return = [Buffy Fungus] } { if ([$0] < 100) { @function_return = [Fungus Master] } { if ([$0] < 110) { @function_return = [Weak Peon] } { if ([$0] < 120) { @function_return = [Confused Peon] } { if ([$0] < 130) { @function_return = [Ordinary Peon] } { if ([$0] < 140) { @function_return = [Cheerful Peon] } { if ([$0] < 150) { @function_return = [Powerful Peon] } { if ([$0] < 160) { @function_return = [Poor Mercenary] } { if ([$0] < 170) { @function_return = [Lower Class Mercenary] } { if ([$0] < 180) { @function_return = [Middle Class Mercenary] } { if ([$0] < 190) { @function_return = [Upper Class Mercenary] } { if ([$0] < 200) { @function_return = [Mercenary Guildmaster] } { @function_return = q_to_title_2($0) }}}}}}}}}}}}}}}}}}}}}} } # Converts a given amount of questions into an appropriate title alias q_to_title_2 { if ([$0] < 210) { @function_return = [Apprentice Footman] } { if ([$0] < 220) { @function_return = [Advancing Footman] } { if ([$0] < 230) { @function_return = [Skilled Footman] } { if ([$0] < 240) { @function_return = [Advanced Footman] } { if ([$0] < 250) { @function_return = [Footman Squad Leader] } { if ([$0] < 260) { @function_return = [Unwieldly Thief] } { if ([$0] < 270) { @function_return = [Average Thief] } { if ([$0] < 280) { @function_return = [Skilled Thief] } { if ([$0] < 290) { @function_return = [Very Stealthy Thief] } { if ([$0] < 300) { @function_return = [Master Shadow Thief] } { if ([$0] < 310) { @function_return = [Weak Archer] } { if ([$0] < 320) { @function_return = [Copper Archer] } { if ([$0] < 330) { @function_return = [Silver Archer] } { if ([$0] < 340) { @function_return = [Gold Archer] } { if ([$0] < 350) { @function_return = [Platinum Archer] } { if ([$0] < 360) { @function_return = [Practicing Knight] } { if ([$0] < 370) { @function_return = [Trained Knight] } { if ([$0] < 380) { @function_return = [Skillful Knight] } { if ([$0] < 390) { @function_return = [Silver Knight] } { if ([$0] < 400) { @function_return = [Golden Knight] } { @function_return = [6God of Trivia] }}}}}}}}}}}}}}}}}}}} } # Shutdown routine for the bot. This will save the critical variables and then quit IRC. alias shutdown { /sve /quit } alias adminpass { @trivia.ADMINPASS = [$0] echo Your administrator password has been changed sve } # Save routine for storing various statistical variables for the trivia script. This # routine has been adapted from the PurePak script. Credit is hereby given. alias sve { foreach trivia.SCORE ii { # Update the top trivia record if the old one has been broken if (trivia[SCORE][$ii] > trivia.bestscore) { @trivia.bestscore = trivia[SCORE][$ii] @trivia.bestname = decode($ii) } } @ LF = [${HOME}/TriviaScript/$trivia.SAVEFILE] @ res = delete($LF) @ FHANDLE = open($LF w) if (FHANDLE > 0) { @res = write( $FHANDLE # Trivia version $trivia.VERSION saved settings file ) @res = write( $FHANDLE # Written $stime($time()) ) @res = write( $FHANDLE # ) @res = write( $FHANDLE @ trivia[ADMINPASS] = [$trivia[ADMINPASS]] ) @res = write( $FHANDLE # Flag to indicate loading of stat file ) @res = write( $FHANDLE @ trivia[stat_loaded] = [1]) @res = write( $FHANDLE # Random seeding value ) @res = write( $FHANDLE @ trivia[randomvar] = [$trivia[randomvar]] ) @res = write( $FHANDLE # Top trivia score holder ) @res = write( $FHANDLE @ trivia[bestname] = [$trivia[bestname]] ) @res = write( $FHANDLE @ trivia[bestscore] = [$trivia[bestscore]] ) @res = write( $FHANDLE # Number of points the player has ) foreach trivia.SCORE ii { @res = write( $FHANDLE @trivia.SCORE.$ii = [$trivia.SCORE[$ii]] )} @res = write( $FHANDLE # Customized titles for players ) foreach trivia.SELF_TITLE ii { @res = write( $FHANDLE @trivia.SELF_TITLE.$ii = [$trivia.SELF_TITLE[$ii]] )} @res = write( $FHANDLE echo *** Saved settings loaded from $LF ) @res = close( $FHANDLE ) echo *** Current settings saved to $LF } { echo *** Could not open $LF ! } ^assign -res ^assign -FHANDLE } # Help system which private notices a help menu to people who type !help in the channel. on -public "* * !help" { ^notice $0 Please type 4/msg $N !help <topic> to receive help on specific topics: ^notice $0 01. General info: copyright, general, start_game ^notice $0 02. Special features: daily_double ^notice $0 03. Stat related: title, title_kill ^notice $0 04. Admin control: add, reset, save, start, stop, sub, wipe } # General information help system # Respond to trivia answers sent as a regular message. Calls $check_active() to see whether # a question is currently being shown. $check_active() will also filter out commands and # execute them. on -public "* *" { # in a public handler $0 is the sender, $1 is the channel $2- is the message $handle_public($0 $2-) } # respond to private messages on -msg "* *" { # in a private handler $0 is the sender, $1- is the message $handle_private($0 $1-) } # Hook to detect changes in nickname so we can update the score database so the points # will move with the person. on -channel_nick "* * *" { ^timer 1 /update_name $1 $2 } # this call will start up the script trivia